#ifndef _COAP_CLIENT_H_
#define _COAP_CLIENT_H_

#include <stddef.h>

// unsigned short* listen_server_status();

/**
* Check coap server active status online or offline
* the return is a pointer parse to obtain the value. 
* 
*
* @return       if it is zero means that server offline 
                or already connected, or it is one  
*               means that the server is online we must manual initial connection .
*                                  
*/
unsigned short*
check_server_active_status();

/**
* Try to listen coap server
* 
* @param host          the server host.
* @param port          the server port default is 5683.
*
* @return               the value is zero mean it is not need continue listen
*/
unsigned short
listen_connect_server(const char* host, const char* port);

unsigned short coap_signal_state();

unsigned short check_server_network_status();

/*
@descryption:
  initial global uri
@
@Author: jiang_c
@Datetime: Mon Dec 2 2024
*/

/**
* initial global uri must call befer create_session
* when we bind server host and put or get server resource 
* This function returns 
* the value is zero if success or a value less than zero
* on error.
*
* @param host          the server host.
* @param port          the server port default is 5683.
* @param path          the server resource path default is "data"
*
* @return                 The value is zero on success, or a value
*                         less than zero on error.
*/

short int
init_global_uri(char* host, char* port, char* path);

/**
* must call after init_global_uri to create coap session
* the value is zero if success or a value less than zero
* on error.
*
* @return                 TThe value is zero on success, or a value
*                         less than zero on error.
*/
short int 
create_session();

/**
* when both init_global_uri and create_session are called success
* we can use this function enter coap events loop,
  wait send message to server per time.
* 
* however server host has changed, we must frist release session 
* reset init_global_uri and create_session
*
* This function returns 
* the value is zero if success or a value less than zero
* on error.
*
* @param m          The CoAP provide method
* @param timeout_ms Minimum number of milliseconds to wait for new messages before returning. 
                    If zero the call will block until at least one packet is sent or received.
* @param data       the data want to send server
* @param len        the data length
* @return number of milliseconds spent or @c  if there was an error
*/
int once_send_message(int m, int timeout_ms, char* data, size_t len);

/**
* Release coap session and clean memory
* we should call it befer exit to prevent memory leak
*/
void
release_session();
#endif